﻿using System;

namespace FpAgain.OOP
{
  class TreePrint
  {
    class ToStringVisitor : IVisitor
    {
      public mutable text : string = "";
      
      public Visit(sum : VisitableTree.Sum) : void {
        sum.l.AcceptVisitor(this);
        text += "+";
        sum.r.AcceptVisitor(this);
      }
      
      public Visit(sin : VisitableTree.Sin) : void {
        text += "sin(";
        sin.op.AcceptVisitor(this);
        text += ")";
      }
      
      public Visit(var : VisitableTree.Variable) : void {
        text += var.name;
      }
    }
    
    public Print(tree : VisitableTree) : void {
      def visitor = ToStringVisitor();
      tree.AcceptVisitor(visitor);
      Console.WriteLine(visitor.text);
    }
  }
}